<template>
  <div class="dashboard-container">
    <div class="app-container">
      <page-tools :show-before="true">
        <span slot="before">共{{ total }}条记录</span>
        <template slot="after">
          <el-button size="small" type="warning">导入</el-button>
          <el-button size="small" type="danger">导出</el-button>
          <el-button size="small" type="primary">新增员工</el-button>
        </template>
      </page-tools>
      <!-- 放置表格和分页 -->
      <el-card>
        <el-table border :data="employeeList">
          <el-table-column label="序号" sortable="" type="index">
            <template #default="obj">
              <!-- 新增数据序号 -->
              <!-- 当前页面的前一页乘于没页的数量,再加上当前页面的数量加一 -->
              {{ (pageSetting.page - 1) * pageSetting.size + (obj.$index + 1) }}
            </template>
          </el-table-column>
          <el-table-column label="姓名" sortable="" prop="username" />
          <el-table-column label="工号" sortable="" prop="workNumber" />
          <el-table-column label="聘用形式" sortable="" prop="formOfEmployment" />
          <el-table-column label="部门" sortable="" prop="departmentName" />
          <el-table-column label="入职时间" sortable="" prop="timeOfEntry" />
          <el-table-column label="账户状态" sortable="" prop="workNumber" />
          <el-table-column label="操作" sortable="" fixed="right" width="280">
            <template>
              <el-button type="text" size="small">查看</el-button>
              <el-button type="text" size="small">转正</el-button>
              <el-button type="text" size="small">调岗</el-button>
              <el-button type="text" size="small">离职</el-button>
              <el-button type="text" size="small">角色</el-button>
              <el-button type="text" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <el-row type="flex" justify="center" align="middle" style="height: 60px">
          <el-pagination
            layout="prev, pager, next"
            :page-size="pageSetting.size"
            :total="total"
            @current-change="currentChange"
          />
        </el-row>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getEmployeeList } from '@/api/employees'
export default {
  data() {
    return {
      employeeList: [], // 员工列表
      total: 0, // 总页数
      pageSetting: {
        page: 1, // 页码
        size: 5 // 每页条数
      }
    }
  },
  created() {
    // 调用获取列表事件
    this.getEmployeeListFn()
  },
  methods: {
    // 获取员工列表
    async  getEmployeeListFn() {
      // 传入页码和每页条数
      const { rows, total } = await getEmployeeList(this.pageSetting)
      // console.log(63, rows)
      // 赋值员工列表
      this.employeeList = rows
      // 赋值总页数
      this.total = total
    },
    // 点击切换当前页面
    currentChange(newPage) {
      this.pageSetting.page = newPage
      // 调用获取列表事件重新渲染
      this.getEmployeeListFn()
    }
  }
}
</script>

<style>

</style>
